/**
 * 
 */
package com.hp.sso.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.web.servlet.View;

import com.hp.sso.MyConnectView;
import com.hp.sso.weixin.connet.WeixinConnectionFactory;

/**
 * 微信登录配置
 * 
 * @author hp
 *
 */
@Configuration
@ConditionalOnProperty(prefix = "weixin", name = "app-id")
public class WeixinAutoConfiguration extends SocialAutoConfigurerAdapter {

	@Value("${weixin.app-id}")
	private String wxAppId;
	
	@Value("${weixin.app-secret}")
	private String wxAppSecret;
	
	@Value("${weixin.providerId}")
	private String wxProviderId;
	
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter
	 * #createConnectionFactory()
	 */
	@Override
	protected ConnectionFactory<?> createConnectionFactory() {
		return new WeixinConnectionFactory(wxProviderId, wxAppId,
				wxAppSecret);
	}
	
	@Bean({"connect/weixinConnect", "connect/weixinConnected"})
	@ConditionalOnMissingBean(name = "weixinConnectedView")
	public View weixinConnectedView() {
		return new MyConnectView();
	}
	
	
	
	
	public String getWxAppId() {
		return wxAppId;
	}



	public void setWxAppId(String wxAppId) {
		this.wxAppId = wxAppId;
	}



	public String getWxAppSecret() {
		return wxAppSecret;
	}



	public void setWxAppSecret(String wxAppSecret) {
		this.wxAppSecret = wxAppSecret;
	}



	public String getWxProviderId() {
		return wxProviderId;
	}



	public void setWxProviderId(String wxProviderId) {
		this.wxProviderId = wxProviderId;
	}
	
}
